package Com.javaserver.servlet;

import Com.javaserver.dao.admidserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class loginservlet extends HttpServlet {
    admidserver admidserver = new admidserver();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        String acc =  req.getParameter("account");
        String paw =  req.getParameter("password");

        if (admidserver.login(acc,paw)){
            req.getSession().setAttribute("msg","登录成功");
            resp.sendRedirect(req.getContextPath()+"/login.jsp");
        }else{
            req.getSession().setAttribute("msg","登录失败");
            resp.sendRedirect(req.getContextPath()+"/main.jsp");
        }
    }
}
